﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PMSSys
{
    public partial class PaymentListView : Form
    {
        public PaymentListView(patientController ppcontroller, Patient pObject)
        {
            InitializeComponent();
            paymentcontroller = new paymentController();
            paymentcontroller.DbConnect = ppcontroller.DbConnect;
            this.pObject = pObject;
            DataTable lst = paymentcontroller.getDataTable(pObject.PatientID);
            dataGridView1.DataSource = lst;
            dataGridView1.Columns[0].Visible = false;
        }
        private paymentController paymentcontroller;
        private Patient pObject;

        private void button6_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void newPaymentButton_Click(object sender, EventArgs e)
        {
            PaymentView newWindow = new PaymentView(String.Empty, paymentcontroller);
            newWindow.ShowDialog();
            DataTable lst = paymentcontroller.getDataTable(pObject.PatientID);
            dataGridView1.DataSource = lst;
            dataGridView1.Columns[0].Visible = false;
        }

        private void viewPaymentButton_Click(object sender, EventArgs e)
        {
            String id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            PaymentView newWindow = new PaymentView(id, paymentcontroller);
            newWindow.ShowDialog();
            DataTable lst = paymentcontroller.getDataTable(pObject.PatientID);
            dataGridView1.DataSource = lst;
            dataGridView1.Columns[0].Visible = false;
        }

        private void removeMarkerButton_Click(object sender, EventArgs e)
        {
            //logic for removing the selected from list
            DataTable lst = paymentcontroller.getDataTable(pObject.PatientID);
            dataGridView1.DataSource = lst;
            dataGridView1.Columns[0].Visible = false;
        }

        private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            if (dataGridView1.RowCount == 0)
            {
                viewPaymentButton.Enabled = false;
                removeMarkerButton.Enabled = false;
            }
            else
            {
                viewPaymentButton.Enabled = true;
                removeMarkerButton.Enabled = true;
            }
        }

        private void PaymentListView_Load(object sender, EventArgs e)
        {
            ToolTip t1 = uiUtility.tooltips();
            t1.SetToolTip(this.newPaymentButton, "New Payment");
            t1.SetToolTip(this.viewPaymentButton, "View Payment");
            t1.SetToolTip(this.removeMarkerButton, "Remove Bone Marrow Reading");
            t1.SetToolTip(this.button6, "Back");
        }
    }
}
